import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
// import componentsRouter from './modules/components'
// import chartsRouter from './modules/charts'
// import tableRouter from './modules/table'
// import nestedRouter from './modules/nested'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index'),
    hidden: true,
    meta: { affix: false }
  },
  {
    path: '/auth-redirect',
    name: 'authRedirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true,
    meta: { affix: false }
  },
  {
    path: '/company',
    name: 'companyRegister',
    redirect: '/company/register',
    component: () => import('@/layout/components/AppMain.vue'),
    hidden: true,
    meta: { affix: false },
    children: [
      {
        path: 'register',
        component: () => import('@/views/company/Register'),
        name: 'register',
        meta: { title: '公司注册' }
      }
    ]
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/protocol',
    name: 'protocol',
    component: () => import('@/views/error-page/protocol'),
    hidden: true,
    meta: { title: '协议签署', icon: 'dashboard', affix: false }
  },
  {
    path: '/show',
    // component: () => import('@/views/visitor/showNew'),
    component: () => import('@/views/visitor/show'),
    hidden: true,
    meta: { title: '访客展示', icon: 'dashboard', affix: true }
  },
  {
    path: '/prompt',
    name: 'prompt',
    component: () => import('@/views/company/prompt'),
    hidden: true,
    meta: { title: '注册完成提示', icon: 'dashboard', affix: false }
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('@/views/company/Register'),
    hidden: true,
    meta: { title: '返回注册页面', icon: 'dashboard', affix: false }
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'page', affix: true }
      }
    ]
  },
  {
    path: '/personnel/show',
    component: () => import('@/views/error-page/401')
  },
  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/profile/index'),
        name: 'Profile',
        meta: { title: 'Profile', icon: 'user', noCache: true }
      }
    ]
  },
  {
    path: '/dormitory/room',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'details/:id',
        component: () => import('@/views/dormitory/roomDetails'),
        name: 'roomDetails',
        meta: { title: '房间详情', noCache: true }
      }
    ]
  },
  {
    path: '/personnel-files',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'show/:id',
        component: () => import('@/views/personnel-files/show'),
        name: 'personnelShow',
        meta: { title: '人事档案详情', noCache: true }
      }
    ]
  },
  {
    path: '/entry/show',
    component: Layout,
    hidden: true,
    children: [
      {
        path: ':id',
        component: () => import('@/views/entry/show'),
        name: 'entryShow',
        meta: { title: '面试审核详情', noCache: true }
      }
    ]
  },
  {
    path: '/entry/finish/show',
    component: Layout,
    hidden: true,
    children: [
      {
        path: ':id',
        component: () => import('@/views/entry/finishShow'),
        name: 'finishShow',
        meta: { title: '入职审核详情', noCache: true }
      }
    ]
  },
  {
    path: '/examination/details',
    component: Layout,
    hidden: true,
    children: [
      {
        path: ':id',
        component: () => import('@/views/examination/details'),
        name: 'examinationDetails',
        meta: { title: '试卷详情', noCache: true }
      }
    ]
  },
  {
    path: '/train/detail',
    component: Layout,
    hidden: true,
    children: [
      {
        path: ':id',
        component: () => import('@/views/train/detailNew'),
        name: 'trainDetail',
        meta: { title: '课程详情', noCache: true }
      }
    ]
  },
  {
    path: '/dormitory/show',
    component: Layout,
    hidden: true,
    children: [
      {
        path: ':id',
        component: () => import('@/views/dormitory/show'),
        name: 'dormitoryShow',
        meta: { title: '宿舍详情', noCache: true }
      }
    ]
  },
  {
    path: '/examination/detail',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () =>
          import('@/views/examination/PaperDetailNew/PaperDetailNew.vue'),
        name: 'examinationDetail',
        meta: { title: '试卷详情', noCache: true }
      }
    ]
  },
  {
    path: '/answer/detail/:id',
    name: 'answerDetail',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/examination/staffDetails'),
        name: 'answerDetails',
        meta: { title: '答题详情', noCache: true }
      }
    ]
  },
  {
    path: '/train/list',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/train/list',
        component: () => import('@/views/train/list'),
        name: 'list',
        meta: { title: '详情', noCache: true }
      }
    ]
  },
  {
    path: '/train/learningSituation',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/train/learningSituation',
        component: () => import('@/views/train/learningSituation'),
        name: 'learningSituation',
        meta: { title: '学习情况', noCache: true }
      }
    ]
  },
  {
    path: '/wx-upload',
    name: 'wxUpload',
    component: () => import('@/views/webView/FileUpload.vue'),
    hidden: true,
    meta: { title: '文件上传', icon: 'dashboard', affix: false }
  },
  {
    path: '/base/visit-rule/details',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/visitRule/RuleDetailsNew.vue'),
        name: 'RuleDetails',
        meta: { title: '须知详情', noCache: true }
      }
    ]
  },
  {
    path: '/birthday',
    component: () => import('@/views/birthdayPage/index.vue'),
    hidden: true,
    name: 'Birthday'
    // children: [
    //   {
    //     path: '',
    //     component: () => import('@/views/visitRule/RuleDetails.vue'),
    //     name: 'RuleDetails',
    //     meta: { title: '须知详情', noCache: true }
    //   }
    // ]
  },
  {
    path: '/workflows',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/approvalFlow/workFlows.vue'),
        name: 'workflows',
        meta: { title: '工作流创建', noCache: true }
      }
    ]
  },
  {
    path: '/visit/credentials/:id',
    name: 'visitorCredentials',
    hidden: true,
    component: () => import('@/views/visitor/visitorCredentials.vue'),
    meta: { title: '访客凭证', affix: false }
  },
  {
    path: '/office',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/office/inventory-details',
        component: () =>
          import('@/views/officeSuppliesManagement/goodsDetails.vue'),
        name: 'goodsDetails',
        meta: { title: '库存详情', noCache: true }
      }
    ]
  },
  {
    path: '/map',
    name: 'map',
    hidden: true,
    component: () => import('@/views/commonPage/map.vue'),
    meta: { title: '地图', affix: false }
  },
  {
    path: '/approval',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/approval/detail/:id',
        name: 'approvalRecordDetails',
        hidden: true,
        component: () =>
          import('@/views/approvalFlow/approvalRecordDetails.vue'),
        meta: { title: '审批详情', affix: false }
      }
    ]
  },
  {
    path: '/jump/:id',
    name: 'jump',
    hidden: true,
    component: () => import('@/views/commonPage/jump.vue'),
    meta: { title: 'jump', affix: false }
  },
  {
    path: '/customer-service',
    name: 'customerService',
    hidden: true,
    component: () => import('@/views/commonPage/smartCustomerService.vue'),
    meta: { title: '智能客服', affix: false }
  },
  {
    path: '/conference/weekly/view',
    name: 'weeklyView',
    hidden: true,
    component: () => import('@/views/conferenceRoomAppointment/weeklyView.vue'),
    meta: { title: '会议室预约看板', affix: false }
  },
  {
    path: '/vehicle-service/gps',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/vehicle-service/gps/info/:id',
        component: () => import('@/views/vehicleService/vehicleGps'),
        name: 'vehicleGps',
        meta: { title: '车辆定位' }
      },
      {
        path: '/vehicle-service/gps/history/:id',
        component: () => import('@/views/vehicleService/vehicleGpsHistory'),
        name: 'vehicleGpsHistory',
        meta: { title: '车辆历史轨迹' }
      },
      {
        path: '/vehicle/fence-create',
        component: () => import('@/views/vehicleService/fenceCreate.vue'),
        name: 'fenceCreate',
        hidden: true,
        meta: { title: '车辆围栏设置', affix: false }
      },
      {
        path: '/vehicle/personalVehicle',
        component: () => import('@/views/vehicleService/personalVehicle.vue'),
        name: 'personalVehicle',
        hidden: true,
        meta: { title: '自用车', affix: false }
      },
      {
        path: '/vehicle/approvedVehicleList',
        component: () => import('@/views/vehicleService/approvedVehicleList.vue'),
        name: 'approvedVehicleList',
        hidden: true,
        meta: { title: '通过审批自用车', affix: false }
      }
    ]
  },
  {
    path: '/vehicle-gps',
    component: () => import('@/views/commonPage/vehicleGps.vue'),
    name: 'commonPageVehicleGps',
    hidden: true,
    meta: { title: '车辆定位', affix: false }
  },
  {
    path: '/question',
    component: Layout,
    hidden: true,

    children: [
      {
        path: 'list',
        component: () => import('@/views/qusetionList/list.vue'),
        name: 'QuestionList',
        meta: { title: '题目列表' }
      },
      {
        path: 'create',
        component: () => import('@/views/qusetionList/createQuestion.vue'),
        name: 'CreateQuestion',
        meta: { title: '创建题目' }
      },
      {
        path: 'testPaper',
        component: () => import('@/views/qusetionList/testPaper.vue'),
        name: 'TestPaper',
        meta: { title: '试卷列表' }
      },
      {
        path: 'testExerciseList',
        component: () => import('@/views/qusetionList/testExerciseList.vue'),
        name: 'TestExerciseList',
        meta: { title: '练习测试列表' }
      }
    ]
  }
]

export const asyncRoutes = [

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
